package ner;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class BookCharacter {

	private Set<String> aliases=new HashSet<String>();
	
	private Map<Case,String> declination=new HashMap<Case,String>();
	private Map<Case,Map<String,Integer>> declinationDetails=new HashMap<Case,Map<String,Integer>>();
	
	private Map<String,Integer> synonymCandidates=new HashMap<String,Integer>();
	
	
	private final String name;
	private Gender gender;
	private GrammaticalNumber number;
	private double positiveness;
	
	
	private Map<String,Integer> titles=new HashMap<String,Integer>();
	
	
	private int occurrences;
	
	private List<Integer> sentencesNumbers=new ArrayList<Integer>();
	private List<Integer> positiveSentences=new ArrayList<Integer>() ;
	private List<Integer> negativeSentences=new ArrayList<Integer>();
	
	private List<Integer> lookDescriptionSentences=new ArrayList<Integer>() ;
	private List<Integer> generalDescriptionSentences=new ArrayList<Integer>();
	
	
	
	public Certainity certainity;
	

	
	
	public String getName() {
		return name;
	}


	public BookCharacter(String name,boolean foundUppercasedInTheMiddle){
		
		this.name=name;
		this.occurrences=1;
		this.certainity=new Certainity();
		this.certainity.foundUppercasedInTheMiddle=foundUppercasedInTheMiddle;
		
	}
	
	public BookCharacter(String name,Set<String> aliases,Certainity certainity, int occurences){
		
		this.name=name;
		this.aliases=aliases;		
		this.certainity=certainity;
		this.occurrences=occurences;

		
	}
	/*
	
	public boolean decreaseCertainity(int arg){
		
		if(certainity-arg<1)
			return false;
		else{
			certainity=certainity-arg;
			return true;
		}
		
	}

	public void increaseCertainity(int arg){
		
		certainity=certainity+arg;
		
	}
	
	*/
	public int hashCode(){
		
		return name.hashCode();
	
	}
	public boolean equals(Object o){
		
		BookCharacter secondCharacter=(BookCharacter)o;
		return this.name.equals(secondCharacter.getName());
	
	}


	public void increaseOccurrences() {
		this.occurrences+=1;
	}
	


	public int getOccurrencesNumber() {
		return occurrences;
	}


	public static class Certainity{
		
		public boolean foundUppercasedInTheMiddle=false;
		public boolean foundAsOtherNEType=false;
		public int precededByTitle=0;
		
		public String toString(){
			
			StringBuilder sb=new StringBuilder();
			sb.append("\nCertainity:").append("\n");
			sb.append("\tfound in uppercased in the middle:"+foundUppercasedInTheMiddle).append("\n");
			sb.append("\tfound as other named entity type:"+foundAsOtherNEType).append("\n");
			sb.append("\tnumber of times when preceded by title:"+precededByTitle).append("\n");
			return sb.toString();
			
		}
	}
	
	
	public String toString(){
		StringBuilder sb=new StringBuilder();
		sb.append("\n\n---").append(name).append("---\n");
		sb.append("gender:").append(gender).append("\n");
		sb.append("number:").append(number).append("\n");
		sb.append("positiveness:").append(positiveness).append("\n");
		
		
		sb.append("occurrences in text:"+occurrences).append("\n");
	//	sb.append("positive sentences:"+positiveSentences.size()).append("\n");
	//	sb.append("negative sentences:"+negativeSentences.size()).append("\n");
		
		sb.append("aliases:");
		for(String alias:aliases)
			sb.append(alias).append(",");
		sb.append("\n");
	//	sb.append("synonyms:").append("\n");
		
		sb.append("titles:").append("\n");
		for(Map.Entry<String, Integer> entry:titles.entrySet())
			sb.append(entry.getKey()).append(" - ").append(entry.getValue());;
		sb.append("\n").append(certainity.precededByTitle);
		sb.append(certainity.toString());
		
		sb.append("General description:").append("\n");
		for(Integer i:generalDescriptionSentences){
			sb.append(ExtractionTask.sentences.get(i)).append("\n\n");
		}
		sb.append("Look:").append("\n");
		for(Integer i:lookDescriptionSentences){
			sb.append(ExtractionTask.sentences.get(i)).append("\n\n");
		}
		sb.append("POSITIVE SENTENCES").append("\n");
	
		for(Integer i:positiveSentences){
			sb.append(ExtractionTask.sentences.get(i)).append("\n\n");
		}
		sb.append("NEGATIVE SENTENCES").append("\n");
		for(Integer i:negativeSentences){
			sb.append(ExtractionTask.sentences.get(i)).append("\n\n");
		}
		
	
		return sb.toString();
		
	
		
	}
	
	
	public String getDeclinationDescription(){
		
		StringBuilder sb=new StringBuilder();
		sb.append("aliases:").append("\n");
		for(String alias:aliases)
			sb.append(alias).append(" ").append("\n");
	
		sb.append(Case.NOMINATIVE).append(" ").append(declination.get(Case.NOMINATIVE)).append("\n");
		sb.append(Case.GENITIVE).append(" ").append(declination.get(Case.GENITIVE)).append("\n");
		sb.append(Case.DATIVE).append(" ").append(declination.get(Case.DATIVE)).append("\n");
		sb.append(Case.ACCUSATIVE).append(" ").append(declination.get(Case.ACCUSATIVE)).append("\n");
		sb.append(Case.INSTRUMENTAL).append(" ").append(declination.get(Case.INSTRUMENTAL)).append("\n");
		sb.append(Case.LOCATIVE).append(" ").append(declination.get(Case.LOCATIVE)).append("\n");
		sb.append(Case.VOCATIVE).append(" ").append(declination.get(Case.VOCATIVE)).append("\n");
		return sb.toString();
		
	}


	public void setSentencesNumbers(List<Integer> sentencesNumbers) {
		this.sentencesNumbers = sentencesNumbers;
	}


	public List<Integer> getSentencesNumbers() {
		return sentencesNumbers;
	}


	public void setPositiveSentences(List<Integer> positiveSentences) {
		this.positiveSentences = positiveSentences;
	}


	public List<Integer> getPositiveSentences() {
		return positiveSentences;
	}


	public void setNegativeSentences(List<Integer> negativeSentences) {
		this.negativeSentences = negativeSentences;
	}


	public List<Integer> getNegativeSentences() {
		return negativeSentences;
	}


	public void setGender(Gender gender) {
		this.gender = gender;
	}


	public Gender getGender() {
		return gender;
	}




	public Map<Case,String> getDeclination() {
		return declination;
	}


	public void setTitles(Map<String,Integer> titles) {
		this.titles = titles;
	}


	public Map<String,Integer> getTitles() {
		return titles;
	}


	public void setAliases(Set<String> aliases) {
		this.aliases = aliases;
	}


	public Set<String> getAliases() {
		return aliases;
	}


	public void setNumber(GrammaticalNumber number) {
		this.number = number;
	}


	public GrammaticalNumber getNumber() {
		return number;
	}


	public void setDeclinationDetails(Map<Case,Map<String,Integer>> declinationDetails) {
		this.declinationDetails = declinationDetails;
	}


	public Map<Case,Map<String,Integer>> getDeclinationDetails() {
		return declinationDetails;
	}


	public void setDeclination(Map<Case,String> declination) {
		this.declination = declination;
	}


	public void setLookDescriptionSentences(List<Integer> lookDescriptionSentences) {
		this.lookDescriptionSentences = lookDescriptionSentences;
	}


	public List<Integer> getLookDescriptionSentences() {
		return lookDescriptionSentences;
	}


	public void setGeneralDescriptionSentences(
			List<Integer> generalDescriptionSentences) {
		this.generalDescriptionSentences = generalDescriptionSentences;
	}


	public List<Integer> getGeneralDescriptionSentences() {
		return generalDescriptionSentences;
	}


	public void setSynonymCandidates(Map<String,Integer> synonymCandidates) {
		this.synonymCandidates = synonymCandidates;
	}


	public Map<String,Integer> getSynonymCandidates() {
		return synonymCandidates;
	}


	public void setPositiveness(double positiveness) {
		this.positiveness = positiveness;
	}


	public double getPositiveness() {
		return positiveness;
	}


}
